# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=baculum
pkgver=9.6.3
pkgrel=4
pkgdesc="API layer to Baculum WebGUI tool for Bacula Community program"
url="https://bacula.org/"
arch="noarch"
license="AGPLv3"
depends=""
_php=php7
_common_depends="
	$_php-common
	$_php-ctype
	$_php-curl
	$_php-dom
	$_php-json
	$_php-session
	$_php-xml
	"
_api_depends="
	$_php-bcmath
	$_php-mysqlnd
	$_php-pdo
	$_php-pgsql
	"
_web_depends="
	$_php-mbstring
	"
_apache_depends="apache2 $_php-apache2"
_lighttpd_depends="lighttpd lighttpd-mod_auth $_php-cgi"
makedepends="
	$_common_depends
	$_apache_depends
	$_api_depends
	$_lighttpd_depends
	$_web_depends
	"
pkggroups="www-data"
install=""
subpackages="$pkgname-common:_common
	$pkgname-api:_api
	$pkgname-web:_web
	$pkgname-api-apache2:_api_apache2
	$pkgname-api-lighttpd:_api_lighttpd
	$pkgname-web-apache2:_web_apache2
	$pkgname-web-lighttpd:_web_lighttpd
	"
source="https://downloads.sourceforge.net/project/bacula/bacula/$pkgver/bacula-gui-$pkgver.tar.gz
	 fix-missing-common-pages.patch
	 "
builddir="$srcdir/"bacula-gui-$pkgver/baculum

build() {
	:
}

check() {
	:
}

package() {
	mkdir -p "$pkgdir"/etc/baculum
	make -j1 DESTDIR="$pkgdir" HTTPDNAME=apache2
	# will be symlinks
	rmdir "$pkgdir"/usr/share/baculum/htdocs/assets \
		"$pkgdir"/usr/share/baculum/htdocs/protected/runtime \
		"$pkgdir"/var/cache/baculum

	chgrp -R www-data "$pkgdir"/etc/baculum/Config-*
	chmod g+w "$pkgdir"/etc/baculum/Config-*
	chmod g+r "$pkgdir"/etc/baculum/Config-*/baculum.users
}

_common() {
	pkgdesc="Common libraries for Baculum"
	depends="$_common_depends"
	amove usr/share/baculum/htdocs/protected/Common \
		usr/share/baculum/htdocs/protected/application.xml \
		usr/share/baculum/htdocs/framework \
		usr/share/baculum/htdocs/themes \
		usr/share/baculum/htdocs/LICENSE \
		usr/share/baculum/htdocs/AUTHORS \
		usr/share/baculum/htdocs/README \
		usr/share/baculum/htdocs/INSTALL \
		usr/share/baculum/htdocs/index.php
	install -d -m775 -g www-data "$subpkgdir"/var/cache/baculum \
		"$subpkgdir"/var/log/baculum
	ln -s /var/cache/baculum \
		"$subpkgdir"/usr/share/baculum/htdocs/assets
	ln -s /var/cache/baculum \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/runtime
	ls -la "$subpkgdir"/var/cache/baculum
}

_api() {
	pkgdesc="Baculum API files"
	depends="$pkgname-common=$pkgver-r$pkgrel $_api_depends"
	amove \
		usr/share/baculum/htdocs/protected/API
	# will be symlinks
	rm -r "$subpkgdir"/usr/share/baculum/htdocs/protected/API/Config \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/API/Logs
	ln -s /var/cache/baculum "$subpkgdir"/usr/share/baculum/htdocs/protected/API/Logs
}

_web() {
	pkgdesc="Baculum Web files"
	depends="$pkgname-common=$pkgver-r$pkgrel $_web_depends"
	amove \
		usr/share/baculum/htdocs/protected/Web
	# will be symlinks
	rm -r "$subpkgdir"/usr/share/baculum/htdocs/protected/Web/Config \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/Web/Logs
	ln -s /var/cache/baculum "$subpkgdir"/usr/share/baculum/htdocs/protected/Web/Logs
}

_api_apache2() {
	pkgdesc="Apache configuration for Baculum API"
	depends="$pkgname-api $_apache_depends"
	amove etc/baculum/Config-api-apache \
		etc/apache2/conf.d/baculum-api.conf
	mkdir -p "$subpkgdir"/usr/share/baculum/htdocs/protected/API
	ln -s /etc/baculum/Config-api-apache \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/API/Config
}

_api_lighttpd() {
	pkgdesc="Lighttpd configuration for Baculum API"
	depends="$pkgname-web $_lighttpd_depends"
	amove etc/baculum/Config-api-lighttpd \
		etc/baculum/baculum-api-lighttpd.conf
	mkdir -p "$subpkgdir"/usr/share/baculum/htdocs/protected/API
	ln -s /etc/baculum/Config-api-lighttpd \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/API/Config
}

_web_apache2() {
	pkgdesc="Apache configuration for Baculum WebGUI"
	depends="$pkgname-web $_apache_depends"
	amove etc/baculum/Config-web-apache \
		etc/apache2/conf.d/baculum-web.conf
	mkdir -p "$subpkgdir"/usr/share/baculum/htdocs/protected/Web
	ln -s /etc/baculum/Config-web-apache \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/Web/Config
}

_web_lighttpd() {
	pkgdesc="Lighttpd configuration for Baculum WebGUI"
	depends="$pkgname-web $_lighttpd_depends"
	amove etc/baculum/Config-web-lighttpd \
		etc/baculum/baculum-web-lighttpd.conf
	mkdir -p "$subpkgdir"/usr/share/baculum/htdocs/protected/Web
	ln -s /etc/baculum/Config-web-lighttpd \
		"$subpkgdir"/usr/share/baculum/htdocs/protected/Web/Config
}

sha512sums="1c23523cea4554eb4fbddfd5372567456c1a0df5752b063a5336e33ab1739ea288fb83355a698f54ee576bbe022aa12252e0a9d9942adbdd9c5bda627a16e339  bacula-gui-9.6.3.tar.gz
6c87cd9c4e2946077b9f0204cccf231b1e4f70620b18590511a84859b391acbc20ee8471c6d7b1c0e62b1b64ee2d77e39aee600b3ea474131cc39510e830155b  fix-missing-common-pages.patch"
